package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;

import java.util.ArrayList;
import java.util.List;

public class BallPulseRiseIndicator extends BaseIndicatorController{
    @Override
    public void draw(Canvas canvas, Paint paint) {
        float radius=getWidth()/10;
        canvas.drawCircle(getWidth()/4,radius*2,radius,paint);
        canvas.drawCircle(getWidth()*3/4,radius*2,radius,paint);

        canvas.drawCircle(radius,getHeight()-2*radius,radius,paint);
        canvas.drawCircle(getWidth()/2,getHeight()-2*radius,radius,paint);
        canvas.drawCircle(getWidth()-radius,getHeight()-2*radius,radius,paint);
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();
        AnimatorValue scaleAnim = new AnimatorValue();
        scaleAnim.setLoopedCount(2500);
        scaleAnim.setCurveType(Animator.CurveType.LINEAR);
        scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                getTarget().setRotation(v);
            }
        });
        scaleAnim.start();
        animators.add(scaleAnim);
        return animators;
    }
}
